﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using bdnt_pets_system.Tools;
using bdnt_pets_system.SystemServiceReference;
using bdnt_pets_system_Entity;
using bdnt_pets_system.Resources;

namespace bdnt_pets_system.PageViews.SystemViews
{
    public partial class UserManagerControl : BaseUserControl
    {        
        SystemServiceReference.SystemServiceClient sysClient;

        public UserManagerControl()
        {
            InitializeComponent();            
            sysClient = new SystemServiceReference.SystemServiceClient();
            InitEvent();
            QueryData();
        }

        void InitEvent()
        {         
            sysClient.GetEmployeeObjListConditionCompleted += new EventHandler<SystemServiceReference.GetEmployeeObjListConditionCompletedEventArgs>(sysClient_GetEmployeeObjListConditionCompleted);
            sysClient.DeleteEmployeeObjCompleted += new EventHandler<DeleteEmployeeObjCompletedEventArgs>(sysClient_DeleteEmployeeObjCompleted);
            btnSs.Click += new RoutedEventHandler(btnSs_Click);
            btnCs.Click += new RoutedEventHandler(btnCs_Click);
            btnNewObj.Click += new RoutedEventHandler(btnNewObj_Click);
        }

        void sysClient_DeleteEmployeeObjCompleted(object sender, DeleteEmployeeObjCompletedEventArgs e)
        {
            if (e.Result) 
                QueryData(); 
        }

        void sysClient_GetEmployeeObjListConditionCompleted(object sender, SystemServiceReference.GetEmployeeObjListConditionCompletedEventArgs e)
        {
            gdList.ItemsSource = e.Result;
        }

        void QueryData()
        {
            sysClient.GetEmployeeObjListConditionAsync(tbMc.Text);
        }

        void btnNewObj_Click(object sender, RoutedEventArgs e)
        {
            var cupage = new NewUserControl();
            App.ToPage(cupage);//跳转页面
        }
        void btnCs_Click(object sender, RoutedEventArgs e)
        {
            tbMc.Text = "";
        }

        void btnSs_Click(object sender, RoutedEventArgs e)
        {
            QueryData();
        }      

        private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            sysClient.CloseAsync();
            var cuObj = (sender as HyperlinkButton).Tag as Tbl_Employee;
            var cupage = new NewUserControl(cuObj.Id);
            App.ToPage(cupage);//跳转页面
        }

        private void HyperlinkButton_Click_1(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show(MyStrings.qdyscm,MyStrings.ts, MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                return;
            var cuObj = (sender as HyperlinkButton).Tag as Tbl_Employee;
            sysClient.DeleteEmployeeObjAsync(cuObj.Id);
        }
    }
}
